import asyncio
import datetime

port = 13000
async def handle_client(reader, writer):
    now = datetime.datetime.now()
    formatted_date = now.strftime("%Y_%m_%d_%H_%M_%S")
    print(f"transmitting {formatted_date}")
    cnt = 0
    while True:
        print(f"enter {cnt}")
        cnt += 1
        data = await reader.read(8192)
        if data:
            len = len(data)
            print(f"Received {len}",flush=True)

        else:
            break
    print("Closing the connection")
    writer.close()
    
async def datsrv():
    server = await asyncio.start_server(handle_client, '0.0.0.0', port)

    addr = server.sockets[0].getsockname()
    print(f'Serving on {addr}')

    return server
async def main():
    srv = await datsrv()
    async with srv:
        await srv.serve_forever()
if __name__ == '__main__':
    asyncio.run(main())
    
    